<?php
/**
 * Created by PhpStorm.
 * User: Silence
 * Date: 2017-07-12
 * Time: 14:18
 */

namespace App\Http\Controllers\Admin;

use App\Base\BaseFunc;
use App\Base\Power;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class AdminController extends Controller
{
    public function adminLogin()
    {
        return view("admin.adminLogin");
    }

    public function adminLogins(BaseFunc $baseFunc)
    {
        $input = Input::only('admin_name','admin_password');
        $name = 'admin';
        $password = 'admin';
        if ($input['admin_name'] == $name && $input['admin_password'] == $password)
        {
            session(['admin_id' => 1]);
            $baseFunc->setRedirectMessage(true,'欢迎来到寻医问药后台管理',NULL,'/searchBusiness');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'登陆错误，请重新登陆！',NULL,'/adminLogin');
        }
    }

    public function adminLogout(BaseFunc $baseFunc)
    {
        session(["admin_id"=>NULL]);
        $baseFunc ->setRedirectMessage(true,"您已退出登录",NULL,"/adminLogin");
    }

    public function searchBusiness()
    {
        $data['businessData'] = DB::table('business')
            ->where('business_status',1)
            ->get();
        return view('/admin.searchBusiness',$data);
    }

    public function checkBusiness()
    {
        $data['businessData'] = DB::table('business')
            ->where('business_status',0)
            ->get();
        return view('/admin.checkBusiness',$data);
    }

    public function changeBusiness(BaseFunc $baseFunc)
    {
        $input = Input::only('success');
        $value['business_status'] = 1;
        //dd($input['success']);
        DB::table('business')
            ->where('business_id',$input['success'])
            ->update($value);
        $baseFunc->setRedirectMessage(true,'审核通过',NULL,'/searchBusiness');
    }

    public function delBusiness(BaseFunc $baseFunc)
    {
        $input = Input::only('false');
        DB::table('business')
            ->where('business_id',$input['false'])
            ->delete();
        $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchBusiness');
    }

    public function searchUser()
    {
        $data['userData'] = DB::table('user')->get();
        return view('/admin.searchUser',$data);
    }
}